import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:ruitmentapp/personnel/widget/zj_tabbar.dart';
import 'package:ruitmentapp/core/extension/create_materialColor.dart';
import 'package:ruitmentapp/core/shared/size_fit.dart';
import 'package:ruitmentapp/personnel/request/zj_personnel_request.dart';
import 'package:ruitmentapp/personnel/model/zj_homeposition_model.dart';
import 'zj_tabbar_two_page.dart';

class ACETabBarPage extends StatefulWidget {
  @override
  _ACETabBarPageState createState() => _ACETabBarPageState();
}

class _ACETabBarPageState extends State<ACETabBarPage> with TickerProviderStateMixin {
  TabController _tabController;
  TabController _tabController2;

  var  _tabData01 = [];
  var  _tabData02 = [];
  var  _tabViewData01 = [];
  var  _tabViewData02 = [];

  @override
  void dispose() {
    // _tabController.dispose();
    _tabController2.dispose();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();

    ZJMealRequest.getMealData().then((s) {

      List meals = s['meals'];
      List models = s['models'];

      print('----${s}----');

      setState(() {
        _tabData01 = meals;
        _tabViewData01 = models;
        _tabController2 = TabController(vsync: this, length: _tabData01.length);
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Expanded(
          child:Scaffold(
              appBar: AppBar(
                backgroundColor: const Color(0xFFF3F5F7),
                elevation: 0,
                toolbarHeight: 0,
                bottom: _tabBar05(1, _tabData01, false, true,)
              ),
              body: _tabBarView(1,_tabViewData01),
          )
      )
    ]);
  }

  _tabBarView(type, list) => TabBarView(
      controller: type == 0 ? _tabController : _tabController2,
      children: list ?? []
  );

  _tabBar05(type, list, isLeft, isRight, {isScrollable}) => ACETabBar(
      isScrollable: isScrollable ?? true,
      alignType: ACETabBarAlignType.left,
      labelColor: const Color(0xFF3F4756),
      labelStyle: const TextStyle(color: Colors.green, fontSize: 20),
      labelPadding:const EdgeInsets.only(left: 20),
      unselectedLabelColor: const Color(0xFF77809E),
      unselectedLabelStyle: const TextStyle(color: Colors.purpleAccent, fontSize: 16),
      dragStartBehavior: DragStartBehavior.down,
      indicatorColor:Colors.transparent,
      startIcon: isLeft ? const Padding(
          padding: EdgeInsets.symmetric(horizontal: 10.0),
          child: FlutterLogo())
          : null,
      endIcon: isRight ? GestureDetector(
          onTap: () => print('----endIcon.click----'),
          child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 10.0),
              child: SizedBox(child: Image.asset("assets/images/home/homeadd.png",width: 15,height: 15))
          )
      )
          : null,
      endIcon2: isRight ? GestureDetector(
          onTap: () => print('----endIcon2.click----'),
          child: Padding(
              padding: const EdgeInsets.only(left: 10,right: 20),
              child: SizedBox(child: Image.asset("assets/images/home/homesearch.png",width: 15,height: 15))
          )
      )
          : null,
      controller: type == 0 ? _tabController : _tabController2,
      tabs: list ?? []
  );
}